package org.example.servlet;


import org.example.service.BookService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "deleteHistoryServlet", urlPatterns = "/book/deleteHistory")
public class deleteHistoryServlet extends HttpServlet {

    private BookService bookService = new BookService();

    @Override
    protected void doGet(HttpServletRequest req,
                         HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req,
                          HttpServletResponse resp) throws ServletException, IOException {
        //1. 取参（req当前的页码, 每页的数量, 搜索）

        String book_id = req.getParameter("id");

        int deleteresult = 0;

        deleteresult  = bookService.deleteHistory(req.getSession(),book_id);

        //3. 将结果放入session
        req.getSession().setAttribute("deleteresult ", deleteresult);
        //将count直接作为ajax请求的结果返回
        resp.getWriter().print(deleteresult);


    }
}
